package com.atguigu.day02

import com.atguigu.source.{SensorReading, SensorSource}
import org.apache.flink.api.common.functions.MapFunction
import org.apache.flink.streaming.api.scala._





object MapExample {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(1)
    val value: DataStream[SensorReading] = env.addSource(new SensorSource)

    //可以用匿名函数但我们要习惯实现接口或继承类
    //方式一
    value.map(t=>(
      t.id
    ))

    //方式二
    value.map(new MyMap())


    //方式三
    value.map(new MapFunction[SensorReading,String] {
      override def map(t: SensorReading): String = {

        t.id
      }
    }).print()
    env.execute()
  }

  class MyMap() extends MapFunction[SensorReading,String] {
    override def map(t: SensorReading): String = {
      t.id
    }
  }

}
